﻿using UnityEngine;
using System.Collections;

public class stg2_cardScript : MonoBehaviour {
    bool open = false;
    private AudioSource audio;
    AudioClip ac;
    int tagNum;
	 //Use this for initialization
	void Start () {
        tagNum = int.Parse(gameObject.tag.Substring(4));
        if (stg2_showManager.game_type == 1)
        {
            gameObject.renderer.material.mainTexture = (Texture)Resources.Load("Images/stg2/card" + ((tagNum * 2) - 1));
        }
        if (stg2_showManager.game_type == 2)
        {
            gameObject.renderer.material.mainTexture = (Texture)Resources.Load("Images/stg2/animal" + ((tagNum * 2) - 1));
        }
        gameObject.renderer.material.color = new Color(gameObject.renderer.material.color.r, gameObject.renderer.material.color.g, gameObject.renderer.material.color.b, 0.5f);
        audio = gameObject.GetComponent<AudioSource>();
        if (stg2_showManager.game_type == 1)
        {
            ac = (AudioClip)Resources.Load("Sound Files/fruit" + tagNum);
        }
        if (stg2_showManager.game_type == 2)
        {
            ac = (AudioClip)Resources.Load("Sound Files/animal" + tagNum);
        }
        ac = (AudioClip)Resources.Load("Sound Files/fruit" +tagNum);
        gameObject.transform.Rotate(90, 0, 0);
        
	}
	
	// Update is called once per frame
	void Update () {
        
	}
    
    void OnMouseUp()
    {
        if (open) return;
        animation.Play("wordTouch");						//클릭 시 애니메이션 실행
        tagNum = int.Parse(gameObject.tag.Substring(4));//오브젝트의 tag를 4번째 부터 끝까지 읽어온다.
        audio.PlayOneShot(ac);
    }

    void OpenImage()
    {
        tagNum = int.Parse(gameObject.tag.Substring(4));
        if (stg2_showManager.game_type == 1)
        {
            gameObject.renderer.material.mainTexture = (Texture)Resources.Load("Images/stg2/card" + tagNum * 2);
        }
        if (stg2_showManager.game_type == 2)
        {
            gameObject.renderer.material.mainTexture = (Texture)Resources.Load("Images/stg2/animal" + tagNum * 2);
        }
    }                               //해당 오브젝트의 표면을 해당 이미지로 바꾼다

    void CloseImage()
    {
        tagNum = int.Parse(gameObject.tag.Substring(4));
        if (stg2_showManager.game_type == 1)
        {
            gameObject.renderer.material.mainTexture = (Texture)Resources.Load("Images/stg2/card" + ((tagNum * 2) - 1));
        }
        if (stg2_showManager.game_type == 2)
        {
            gameObject.renderer.material.mainTexture = (Texture)Resources.Load("Images/stg2/animal" + ((tagNum * 2) - 1));
        }
    }

    void turnCard()
    {
       // gameObject.transform.Rotate(0, -180, 0);
    }
}
